// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   FacesUtil.java

package util;

import java.util.Iterator;
import java.util.List;

import javax.faces.application.FacesMessage;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.context.Flash;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
@SuppressWarnings("rawtypes")
public class FacesUtil{

    public FacesUtil() {}

    public static FacesContext getFacesContext() {
        return FacesContext.getCurrentInstance();
    }

    public static ExternalContext getExternalContext() {
        return getFacesContext().getExternalContext();
    }
    
    public static HttpSession getSession() {//return getRequest().getSession();        
    	return (HttpSession) getExternalContext().getSession(false);
    }

    public static HttpServletRequest getRequest() {
        return (HttpServletRequest)getExternalContext().getRequest();
    }

    public static String getRequestContextPath() {
        return getExternalContext().getRequestContextPath();
    }

    public static String getRequestURI() {
        HttpServletRequest servletRequest = (HttpServletRequest)getExternalContext().getRequest();
        return servletRequest.getRequestURI();
    }

    public static Object getRequestAttribute(String attribute) {
        return getRequest().getAttribute(attribute);
    }

    public static void setRequestAttribute(String attribute, Object object) {
        getRequest().setAttribute(attribute, object);
    }

    public static void setSessionAttribute(String attribute, Object object) {
        getSession().setAttribute(attribute, object);
    }

    public static Object getSessionAttribute(String attribute) {
        return getSession().getAttribute(attribute);
    }

    public static String getFullContextRealPath() {
        return getSession().getServletContext().getRealPath("");
    }

    public static String addRedirectToPath(String path) {
        if(!path.contains("?"))
            return (new StringBuilder()).append(path).append("?faces-redirect=true").toString();
        else
            return (new StringBuilder()).append(path).append("&faces-redirect=true").toString();
    }

    public static String addIncludeViewParamsToPath(String path){
        if(!path.contains("?"))
            return (new StringBuilder()).append(path).append("?includeViewParams=true").toString();
        else
            return (new StringBuilder()).append(path).append("&includeViewParams=true").toString();
    }

    public static Flash getFlash() {
        return getExternalContext().getFlash();
    }

    public static void putInFlash(String key, Object value) {
        getFlash().put(key, value);
    }

    private static void addMessage(javax.faces.application.FacesMessage.Severity severity, String message) {
        getFacesContext().addMessage(null, new FacesMessage(severity, message + ".", null));
    }

	public static void addMessages(javax.faces.application.FacesMessage.Severity severity, List messages) {
        String message;
        for(Iterator i$ = messages.iterator(); i$.hasNext(); addMessage(severity, message))
            message = (String)i$.next();

    }

    public static void addError(String message){
        addMessage(FacesMessage.SEVERITY_ERROR, message);
    }

    public static void addErrors(List messages) {
        addMessages(FacesMessage.SEVERITY_ERROR, messages);
    }

    public static void addWarning(String message){
        addMessage(FacesMessage.SEVERITY_WARN, message);
    }

    public static void addWarnings(List messages) {
        addMessages(FacesMessage.SEVERITY_WARN, messages);
    }

    public static void addInfo(String message) {
        addMessage(FacesMessage.SEVERITY_INFO, message);
    }

    public static void addInfos(List messages) {
        addMessages(FacesMessage.SEVERITY_INFO, messages);
    }
}
